package org.platform.processor.diagnose.tree.impl;


import org.platform.mo.bussmo.diagnose.event.AlarmBO;
import org.platform.mo.db.FdDiagnoseTaskTreeNode;
import org.platform.processor.monitor.data.CacheLibraryPO;
import org.platform.tool.util.ComUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 监测点故障树
 *
 * @author FengJie
 * @date 2018/8/1
 */
@Service
public class MonitorFaultTreeNodeImpl extends AbstractFaultTreeNodeDiagnose {

    @Override
    public boolean doExecute(FdDiagnoseTaskTreeNode treeNode) {
        boolean diagnoseStatus = true;
        String knowledgeId = ComUtils.objectToString(treeNode.getKnowledgeid());
        Map<String, AlarmBO> alarmDeviceMap = CacheLibraryPO.getCacheLibraryPO().getAlarmDeviceMap();
        for (Map.Entry<String, AlarmBO> map : alarmDeviceMap.entrySet()) {
            //如果当前的设备ID,在报警库里面,说明异常,反之...
            String key = map.getKey();
            if (key.startsWith(treeNode.getDeviceid()) && key.endsWith(knowledgeId)) {
                diagnoseStatus = false;
                break;
            }
        }
        //客服端为了看到诊断效果 ,这个休眠1秒
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return diagnoseStatus;
    }

}
